import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import RandomUtil from '@/RandomUtil';
import SelectUtil from '@/SelectUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 龙虾锤
 **/
export default class BossSpell_LongXiaChui extends AbilityBase {
    static instance: BossSpell_LongXiaChui;
    buffType: AppBuffType = {
        id: 'buff_BossSpell_LongXiaChui',
        art: this.art,
        name: this.abilityName,
        ubertip: this.ubertip,
        dur: 1,
        interval: 0.2,
        onInterval: this.buffInterval.bind(this),
    };
    buffInterval(buff: Buff) {
        let x = GetUnitX(buff.getParent());
        let y = GetUnitY(buff.getParent());
        DestroyEffect(AddSpecialEffect('Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl', x, y));
        let es = SelectUtil.getEnemyUnitsInRange(buff.getCaster(), 225, x, y);
        DamageSystemInstance.applyAoeMagicDamage(es, buff.getParent(), 300, 'earth');
    }
    constructor(id: string = 'Mxt2') {
        super(id);
        BossSpell_LongXiaChui.instance = this;
        this.init();
        EventManager.onTakeAttack(this.onSpellEffect.bind(this));
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BossAbilityManagerInstance.text('虾**锤', source);
        MovementCommon.hitFly({
            target,
            caster: source,
            speed: 600,
            distance: 600,
            angle: GetUnitFacing(source),
            maxHeight: 0,
        });
        StunSystemIntance.stun(target, 1, source);
        BuffUtil.addBuff(target, this.buffType.id, source);
    }
    onSpellEffect(d: DamageEventData) {
        if (GetUnitAbilityLevel(d.source, this.id) == 0) return;
        let r = RandomUtil.randomPercent();
        if (r > 0.25) return;
        this.cast(0, 0, d.source, d.target);
    }
}
